<%-- 
    Document   : Operador
    Created on : 11/11/2011, 11:45:31 PM
    Author     : Ces
--%>

<%@page import="org.jfree.data.general.DefaultPieDataset"%>
<%@page import="org.jfree.data.general.PieDataset"%>
<%@ page import="PaquetesJL.*" %>
<%@page import="java.sql.ResultSet" %>
<%@page import="java.sql.ResultSetMetaData" %>

<%@page import="org.jfree.chart.*" %>
<%@page import="org.jfree.chart.plot.PlotOrientation" %>
<%@page import="org.jfree.data.category.*" %>
<%@page import="org.jfree.util.TableOrder" %>
<%@page import="java.io.*" %>

<jsp:include page="header.jsp"/>
<jsp:include page="ValidaUsuarioPermiso.jsp?id=Operador.jsp"/>

    <div class="story_title">
        <h2>Operador</h2>
    </div>
    <div class="clear"></div>
    <div class="story_content">
        
    <%
            HttpSession objSesion = request.getSession(false); 
            String usuario = (String)objSesion.getAttribute("username");
            
            if (usuario!=null && usuario.length() > 0 && (String)objSesion.getAttribute("valido")!=null)
            {
                    String username = request.getParameter("username");
                    String password = request.getParameter("password");

                    String sqlServer = pageContext.getServletContext().getInitParameter("sqlServer");
                    String databaseName = pageContext.getServletContext().getInitParameter("databaseName");
                    String userName = pageContext.getServletContext().getInitParameter("userName");
                    String PasswordP = pageContext.getServletContext().getInitParameter("password");
                    String Backup = pageContext.getServletContext().getInitParameter("RutaBackup");

                    byte[] decodedBytes = ConexionBD.decode(PasswordP);
                    String decodedPassword = new String(decodedBytes).trim();

                    ConexionBD Conexion = new ConexionBD(sqlServer, databaseName, userName, decodedPassword, Backup);
                    Conexion.IniciarConexion();
                    
                    //out.println("opcion escogida: " + option);
                    
                    ResultSet r = Conexion.EjecutarConsulta("SELECT DISTINCT id_folio FROM [FOLIO_CHEQUE] WHERE [estado] IS NULL");
                    
                    try {
                        
                    ResultSetMetaData rs = r.getMetaData();
                    
                        %> 
                        
                        <form method="get">
                        <select name="reporte">
                         
                            <%
                        while(r.next())
                        {
                            out.println("<option value="+r.getString(1)+">"+r.getString(1)+"</option>");
                        }
                        
                        
                        %>
                        
                        </select>

            <input type="submit" name="verReporte"/>
        </form>
                        
                        <%

                    } catch (Exception e) { out.println(e.getMessage()); }

                    
                    Conexion.CerrarConexion();
                    
                    
                
    
        
        
            } else {
                
                response.sendRedirect("Autentica.jsp");
            }
        %>
        
        <form method="get" >
            <input id="operar" type="submit" name="verReporte" value="Operar" />
        </form>
        
        <form method="get" >
            <input id="ver reporte" type="submit" name="verReporte2" value="Ver Procesados"/>
        </form>
        
        <%
        
        int option = 0;
        
            if(request.getParameter("verReporte") != null)
            {
                
                
                
                if(request.getParameter("reporte")!=null)
                    option = Integer.parseInt(request.getParameter("reporte"));
                
                
                    String username = request.getParameter("username");
                    String password = request.getParameter("password");

                    String sqlServer = pageContext.getServletContext().getInitParameter("sqlServer");
                    String databaseName = pageContext.getServletContext().getInitParameter("databaseName");
                    String userName = pageContext.getServletContext().getInitParameter("userName");
                    String PasswordP = pageContext.getServletContext().getInitParameter("password");
                    String Backup = pageContext.getServletContext().getInitParameter("RutaBackup");

                    byte[] decodedBytes = ConexionBD.decode(PasswordP);
                    String decodedPassword = new String(decodedBytes).trim();

                    ConexionBD Conexion = new ConexionBD(sqlServer, databaseName, userName, decodedPassword, Backup);
                    Conexion.IniciarConexion();
                    
                    //out.println("opcion escogida: " + option);
                    
                    ResultSet r = Conexion.EjecutarConsulta("SELECT * FROM [FOLIO_CHEQUE] WHERE [estado] IS NULL AND id_folio = " + option);
                    
                    try {
                        
                    ResultSetMetaData rs = r.getMetaData();
                                                
                        while(r.next())
                        {
                            Conexion.EjecutarInstruccion("EXEC OPERADOR " + r.getString(2) + ", " + r.getString(3) + ", " + r.getString(1) + ", " + r.getString(4));   
                            ///out.println("EXEC OPERADOR " + r.getString(2) + ", " + r.getString(3) + ", " + r.getString(1) + ", " + r.getString(4));   
                        }                        

                    } catch (Exception e) { out.println(e.getMessage()); }

                        Conexion.CerrarConexion();
                                     }
             
             if(request.getParameter("verReporte2") != null)
            {       
                 
                  
                
                if(request.getParameter("reporte")!=null)
                    option = Integer.parseInt(request.getParameter("reporte"));
                 
                    String username = request.getParameter("username");
                    String password = request.getParameter("password");

                    String sqlServer = pageContext.getServletContext().getInitParameter("sqlServer");
                    String databaseName = pageContext.getServletContext().getInitParameter("databaseName");
                    String userName = pageContext.getServletContext().getInitParameter("userName");
                    String PasswordP = pageContext.getServletContext().getInitParameter("password");
                    String Backup = pageContext.getServletContext().getInitParameter("RutaBackup");

                    byte[] decodedBytes = ConexionBD.decode(PasswordP);
                    String decodedPassword = new String(decodedBytes).trim();

                    ConexionBD Conexion = new ConexionBD(sqlServer, databaseName, userName, decodedPassword, Backup);
                    Conexion.IniciarConexion();
                    
                    //out.println("opcion escogida: " + option);
                    
                    ResultSet r = Conexion.EjecutarConsulta("EXEC getOPERADOR " + option);
                    
                    try {
                        
                    ResultSetMetaData rs = r.getMetaData();
                    
                        
                        out.println("<br><table cellpadding=5 cellspacing=3 border=1>");
                        out.println("<tr>");
                        
                        for(int i = 1; i<=rs.getColumnCount(); i++)
                        {
                            out.println("<td><b>"+rs.getColumnName(i)+"</b></td>");
                        }
                        out.println("</tr>");
                        
                        while(r.next())
                        {
                            out.println("<tr>");
                            
                            for(int i = 1; i<=rs.getColumnCount(); i++)
                            {
                                out.println("<td>"+r.getString(i)+"</td>");
                            }
                                                
                            out.println("</tr>");
                        }
                        out.println("</table>");

                    } catch (Exception e) { out.println(e.getMessage()); }

                    
                    Conexion.CerrarConexion();
                    
            }
        
        %>
        
        
    </div>




<jsp:include page="footer.jsp"/>